package gui.admin.tablemodel;

import dao.UserDao;
import entity.User;

import javax.swing.table.DefaultTableModel;
import java.util.List;

public class UserTableModel extends DefaultTableModel {
    UserDao userDao = new UserDao();
    String[] tableHeaders = new String[]{"用户编号","姓名","用户密码","卡余额","用户身份"};//用户信息表头
    List userList = null;
    String[][] userData = null;
    public UserTableModel() throws Exception {
        userList = userDao.getAllUsers();
        userData = new String[userList.size()][tableHeaders.length];
        for (int i = 0; i < userList.size(); i++) {
            User user = (User)userList.get(i);
            userData[i][0] = user.getUserId();
            userData[i][1] = user.getUserName();
            userData[i][2] = user.getUserPassword();
            userData[i][3] = String.valueOf(user.getCardBalance());
            userData[i][4] = user.getIdentity();
        }
        this.setDataVector(userData,tableHeaders);
    }
}
